chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
    // message的数据格式取决于发送时的数据
    const { start, lessonFrom, lessonTo, url } = message;

    if (start) {
        // 获取B站某个视频每一集播放时间到脚本
        var time_dom_arr = document.querySelectorAll(".list-box>li>a>div>div:last-child")
        var time_text_arr = []
        for(let i=0; i<time_dom_arr.length; i++){time_text_arr.push(time_dom_arr[i].innerText)}
        // minutes_arr是播放时间的数组
        var minutes_arr = time_text_arr.map(ms=>ms.trim().split(':')[0]*1)
        minutes_arr
        // 计算第from集到第to集的播放分钟合计
        function sum(from, to){
        var count = 0;
        for(var i=from-1; i<to; i++){
            count+=minutes_arr[i]
        }
        return count
        }
        var times = sum(lessonFrom,lessonTo)
        sendResponse(times);
    }
    if(url){
        // alert(1)
        window.open(url)
    }
});